package com.example.Arithmetic.Lettcode;

import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Comparator;

/**
 * 日期：2023/12/31
 * 时间：14:56
 * 描述：无重复区间
 */
public class E01Lettcode435 {
    public int eraseOverlapIntervals(int[][] intervals) {
        Arrays.sort(intervals, Comparator.comparingInt(a -> a[1]));
        int i = 0;
        int coun = 1;
        for (int j = 1; j < intervals.length; j++) {
            if (intervals[j][0] >= intervals[i][1]) {
                i = j;
                coun++;
            }
        }
        return intervals.length - coun;
    }

    @Test
    public void test() {
        int[][] ints=new int[][] {{1,2},{2,3},{3,4},{1,3}};
        E01Lettcode435 e01Lettcode435=new E01Lettcode435();
        System.out.println(e01Lettcode435.eraseOverlapIntervals(ints));
    }
}

